package org.example.myleet.p804;

import java.util.HashSet;

public class Solution {

    /**
     * a-z的摩尔斯电码
     */
    private static final String[] MORSE_CODES = new String[]{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};

    public int uniqueMorseRepresentations(String[] words) {
        HashSet<String> morseWordSet = new HashSet<>();
        for (String word : words) {
            char[] wordCharArr = word.toCharArray();
            StringBuilder sb = new StringBuilder();
            for (char c : wordCharArr) {
                sb.append(MORSE_CODES[c - 'a']);
            }
            morseWordSet.add(sb.toString());
        }
        return morseWordSet.size();
    }
}
